<!-- 上传列表 -->
<template>
  <template v-if="!showUploadFailed">
    <ul class="content-list">
      <li v-for="item in dataList" :key="item.id" class="content-list-item">
        <div class="content-list-item-content">
          <div class="content-info">
            <div class="title-wrap">
              <div class="title">
                <i v-if="item.fileType === 'file'" class="iconfont icon-file-line"></i>
                <i v-else class="iconfont icon-folder-3-line"></i>
                <p :title="item.name">{{ item.name }}</p>
              </div>
              <p :title="item.address">{{ item.address }}</p>
            </div>
            <div class="status">
              <span v-if="item.status === 'uploading'" class="">{{ item?.handleNumber }}/{{ item?.totalNumber }}</span>
              <i v-if="item.status === 'successful'" class="iconfont icon-checkbox-circle-fill success"></i>
              <p v-if="item.status === 'failed'">{{ item?.message }}</p>
            </div>
            <div class="hover-status">
              <div v-if="item.status === 'failed'" class="detail-btn" @click="handleToFailedList(item)">失败详情</div>
              <a-button type="text" class="icon-only-btn" @click="handleRemoveItem(item)">
                <i class="iconfont icon-close-line"></i>
              </a-button>
            </div>
          </div>
          <a-progress v-if="item.status === 'uploading'" class="progress" :show-info="false" :percent="item.progress" size="small" />
        </div>
      </li>
    </ul>
    <div class="clear-all" @click="handleClearAll"><i class="iconfont icon-delete-bin-fill"></i>清空</div>
  </template>

  <template v-else>
    <div class="navigation">
      <a-button type="text" class="icon-only-btn" @click="handleBack"><i class="iconfont icon-arrow-left-line"></i></a-button>
      失败详情（{{ current?.name }}）
    </div>
    <ul v-show="showUploadFailed" class="content-list">
      <template v-for="item in failedDataList" :key="item.id">
        <li class="content-list-item" :class="[`item-${item.id}`]">
          <div class="content-list-item-file">
            <i class="iconfont icon-file-warning-line"></i>
            <p :title="item.name">{{ item.name }}</p>
            <!-- <a-button type="text" class="icon-only-btn" @click="handleRemoveItem(item)">
            <i class="iconfont icon-close-line"></i>
          </a-button> -->
          </div>
        </li>
      </template>
    </ul>
    <div class="footer-wrap">
      <p>失败 {{ current?.failNumber || 0 }}/{{ current?.totalNumber || 0 }}</p>
      <a-button type="default" class="icon-with-btn" size="small" @click="handleRetransmission">
        <i class="iconfont icon-restart-line"></i>重传
      </a-button>
    </div>
  </template>
</template>

<script setup lang="ts">
  import { ref } from 'vue'

  import { LineFileInfo } from '../types/index'

  type ExportListProps = {
    dataList: LineFileInfo[]
    failedDataList: LineFileInfo[]
  }

  withDefaults(defineProps<ExportListProps>(), {
    dataList: () => []
  })

  const emits = defineEmits<{
    (e: 'clear-all'): void
    (e: 'remove', fileInfo: LineFileInfo): void
    (e: 'retransmission', fileInfo: LineFileInfo): void
    (e: 'to-failed-list', fileInfo: LineFileInfo): void
  }>()

  const showUploadFailed = ref(false)

  const handleClearAll = () => {
    emits('clear-all')
  }

  let current = ref()
  const handleToFailedList = (item: LineFileInfo) => {
    showUploadFailed.value = true
    current.value = item
    emits('to-failed-list', item)
  }

  const handleBack = () => {
    showUploadFailed.value = false
    current.value = null
  }

  const handleRemoveItem = (item: LineFileInfo) => {
    emits('remove', item)
  }

  const handleRetransmission = () => {
    showUploadFailed.value = false
    emits('retransmission', current.value as LineFileInfo)
  }
</script>

<style lang="less" scoped>
  @import '../style/common.less';
  @import '@/styles/mixins.less';

  .content-list {
    display: flex;
    overflow: auto;
    padding: 10px 24px 0;
    width: 100%;
    flex: 1;
    border-top: 1px solid @border1;
    flex-direction: column;

    .content-list-item {
      width: 100%;
      border-bottom: 1px solid @border1;

      &:last-child {
        border-bottom: none;
      }

      .content-list-item-content {
        padding: 4px 8px;
        margin: 10px 0;
        width: 100%;
        background: #fff;
        cursor: pointer;

        &:hover {
          background: rgba(0, 0, 0, 0.05);
          border-radius: 2px;

          .content-info .status {
            display: none;
          }

          .content-info .hover-status {
            display: flex;
          }
        }

        .content-info {
          display: flex;
          justify-content: space-between;
          align-items: center;
          width: 100%;

          .title-wrap {
            flex: 1;
            min-width: 0;

            .title {
              display: flex;
              align-items: center;
              width: 100%;
              font-size: 14px;
              color: @text01;
              line-height: 22px;

              > i {
                display: block;
                margin-right: 4px;
                color: @text04;
              }

              > p {
                .elliptical-1();
              }
            }

            > p {
              font-size: 12px;
              font-weight: 400;
              line-height: 20px;
              color: @text03;
              .elliptical-1();
            }
          }

          .status {
            text-align: end;

            .success {
              color: @success;
            }

            > p {
              font-size: 12px;
              font-weight: 400;
              line-height: 20px;
              color: @danger;
            }

            > span {
              font-size: 12px;
              color: rgba(17, 22, 31, 0.75);
              font-weight: 400;
            }
          }

          .hover-status {
            display: none;
            gap: 0 4px;

            .detail-btn {
              display: flex;
              justify-content: center;
              align-items: center;
              width: 60px;
              height: 24px;
              font-size: 12px;
              background: rgba(0, 0, 0, 0.05);
              border-radius: 6px;
              font-weight: 400;
              line-height: 20px;
            }
          }
        }

        .progress {
          margin: 0;

          :deep(.ant-progress-bg) {
            height: 3px !important;
          }
        }
      }

      .active {
        background: rgba(0, 0, 0, 0.05);
        border-radius: 2px;
      }

      .content-list-item-file {
        display: flex;
        align-items: center;
        padding: 0 8px;
        margin: 14px 0;
        height: 24px;
        gap: 0 4px;

        > p {
          font-size: 14px;
          font-weight: 400;
          line-height: 22px;
          .elliptical-1();
        }

        > i {
          display: block;
          color: @text04;
        }

        // &:hover {
        //   background: rgba(0, 0, 0, 0.05);
        //   border-radius: 2px;

        //   .icon-only-btn {
        //     display: flex;
        //   }
        // }

        .icon-only-btn {
          display: none;
          margin-left: auto;
        }
      }
    }
  }

  .navigation {
    display: flex;
    align-items: center;
    padding: 6px 20px;
    border-bottom: 1px solid #f5f5f5;
    background: #fff;
    .font14b();
  }
</style>
